Skip to content

Conversation

@Aditya2755
Copy link
Contributor

Fixes #7883

This PR adds @overload decorators to load_dataset() to help type checkers like Pylance and mypy correctly infer the return type based on the split and streaming parameters.

Changes:

  • Added typing imports (Literal, overload) to load.py
  • Added 4 @overload signatures that map argument combinations to specific return types:
    • split=None, streaming=False -> DatasetDict
    • split specified, streaming=False -> Dataset
    • split=None, streaming=True -> IterableDatasetDict
    • split specified, streaming=True -> IterableDataset

This resolves the Pylance error where to_csv() was not recognized on Dataset objects returned by load_dataset(..., split='train'), since the type checker previously saw the return type as a Union that included types without to_csv().

No runtime behavior changes - this is purely a static typing improvement.

Fixes huggingface#7883

This PR adds @overload decorators to load_dataset() to help type checkers
like Pylance and mypy correctly infer the return type based on the split
and streaming parameters.

Changes:
- Added typing imports (Literal, overload) to load.py
- Added 4 @overload signatures that map argument combinations to specific return types:
  * split=None, streaming=False -> DatasetDict
  * split specified, streaming=False -> Dataset
  * split=None, streaming=True -> IterableDatasetDict
  * split specified, streaming=True -> IterableDataset

This resolves the Pylance error where to_csv() was not recognized on Dataset
objects returned by load_dataset(..., split='train'), since the type checker
previously saw the return type as a Union that included types without to_csv().

No runtime behavior changes - this is purely a static typing improvement.
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great ! lgtm :)

@lhoestq lhoestq merged commit 1a330f3 into huggingface:main Dec 8, 2025
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data.to_csv() cannot be recognized by pylance

3 participants